//
//  InvestProtectionCell.m
//  Kjs-iOS
//
//  Created by cfq on 16/6/3.
//  Copyright © 2016年 jmhz. All rights reserved.
//

#import "InvestProtectionCell.h"
#import "UIColor+KjsColor.h"
#import "DocumentView.h"

@interface InvestProtectionCell()
@property (nonatomic,weak) IBOutlet UIScrollView *scrollview;
@property (nonatomic,strong) NSArray <ItemDocument *> *documents;
@end

@implementation InvestProtectionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.scrollview.showsHorizontalScrollIndicator = FALSE;
    [self.scrollview setBackgroundColor:[UIColor whiteColor]];
    [self sendSubviewToBack:self.contentView];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)initCellWithDocuments:(NSArray *)documents ItemInfo:(ItemInfo *)item
{
    self.documents = documents;

    _financeRequireLab.text = item.gdFinancingRequired;
    _payInfoLab.text = item.gdSrcOfRepayment;
    DocumentView *documentV = [[[NSBundle mainBundle] loadNibNamed:@"DocumentView" owner:self options:nil] firstObject];
    self.scrollview.contentSize = CGSizeMake(documentV.frame.size.width, documentV.frame.size.height * [documents count]);
    for (int i = 0  ; i < [documents count]; i++) {
        DocumentView *documentV = [[[NSBundle mainBundle] loadNibNamed:@"DocumentView" owner:self options:nil] firstObject];
        documentV.document = documents[i];
        documentV.tag = i;
        UITapGestureRecognizer *showInfo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showInformation:)];
        documentV.userInteractionEnabled = YES;
        [documentV addGestureRecognizer:showInfo];
        UIView *contantV = [[UIView alloc] initWithFrame:CGRectMake(0, documentV.frame.size.height * i, documentV.frame.size.width, documentV.frame.size.height)];
        contantV.layer.borderWidth = 1.0 ;
        contantV.layer.borderColor = [UIColor kjsLightGrayColor].CGColor;
        [contantV setBackgroundColor:[UIColor whiteColor]];
        [contantV addSubview:documentV];
        [self.scrollview addSubview:contantV];
    }
}
-(void)showInformation:(id)sender
{
    UIView *view = [[UIView alloc] init];
    UITapGestureRecognizer *tempLP = (UITapGestureRecognizer *)sender;
    view = tempLP.view;
    NSLog(@"第%ld个",view.tag);
    if (self.documents[view.tag].ifHrefValid == 1){
        if (self.showInfo) {
            self.showInfo(self.documents[view.tag].itemInfoMaterialPath,self.documents[view.tag].documentName);
        }
    }
    
}
@end
